let baseUrl = 'https://maomaotou.cn/emergency-study-api/'
// let baseUrl = 'https://hyjd-ycyjydt.com/emergency-study-api/'

/**
 * get（）--api
 * @param obj 参数 url 地址
 * @returns {*}
 */
export function Get(obj,url){
    return new Promise((resolve, reject) => {
        uni.request({
            url: baseUrl + url, //仅为示例，并非真实接口地址。
            data: obj,
            method:'GET',
			header:{Authorization: `Bearer  ${uni.getStorageSync('access_token') ? uni.getStorageSync('access_token') : ''}`},
            success: (res) => {
				if(res.data.code == 401){
					uni.clearStorageSync()
					uni.navigateTo({
						url:"/pages/login/login"
					})
				}else if(res.data.code == 500){
					uni.showToast({
						title: res.data.message,
						icon: 'none'
					})
				}else if(res.data.code == 502){
					uni.clearStorageSync()
					uni.navigateTo({
						url:"/pages/login/login"
					})
				}else{
					resolve(res.data);
				}
            },
            fail(err) {
                reject(err);
            }
        });
    })
}
export function Put(obj,url){
    return new Promise((resolve, reject) => {
        uni.request({
            url: baseUrl + url, //仅为示例，并非真实接口地址。
            data: obj,
            method:'PUT',
			header:{Authorization: `Bearer  ${uni.getStorageSync('access_token') ? uni.getStorageSync('access_token') : ''}`},
            success: (res) => {
				if(res.data.code == 401){
					uni.clearStorageSync()
					uni.navigateTo({
						url:"/pages/login/login"
					})
				}else if(res.data.code == 500){
					uni.showToast({
						title: res.data.message,
						icon: 'none'
					})
				}else if(res.data.code == 502){
					uni.clearStorageSync()
					uni.navigateTo({
						url:"/pages/login/login"
					})
				}else{
					resolve(res.data);
				}
            },
            fail(err) {
                reject(err);
            }
        });
    })
}
/**
 * post（）--api  eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MjQ5NTk1OTcsInN1YiI6ImFkbWluIiwidXNlcl9pZCI6MTM5ODkzMzc3Mzg2NjYxNDc4NCwicm9sZXMiOlsiMSJdfQ.JYVUyNxtK57FzRJ8chCz5TmZK7wx5crJ2SOS0SaRtcw
 * @param obj
 * @returns {*}		eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MjQ5NTk1OTcsInN1YiI6ImFkbWluIiwidXNlcl9pZCI6MTM5ODkzMzc3Mzg2NjYxNDc4NCwicm9sZXMiOlsiMSJdfQ.JYVUyNxtK57FzRJ8chCz5TmZK7wx5crJ2SOS0SaRtcw
 */
export function Post (obj,url) {
    return new Promise((resolve, reject) => {
        uni.request({
            url: baseUrl + url, //仅为示例，并非真实接口地址。
            data: obj,
            method:'POST',
			header:{Authorization: `Bearer  ${uni.getStorageSync('access_token') ? uni.getStorageSync('access_token') : ''}`},
            success: (res) => {
				if(res.data.code == 401){
					uni.clearStorageSync()
					uni.navigateTo({
						url:"/pages/login/login"
					})
				}else if(res.data.code == 500){
					uni.showToast({
						title: res.data.message,
						icon: 'none'
					})
				}else if(res.data.code == 502){
					uni.clearStorageSync()
					uni.navigateTo({
						url:"/pages/login/login"
					})
				}else{
					resolve(res.data);
				}
            },
            fail(err) {
                reject(err)
            }
        });
    })
}
export {
	baseUrl
}